package department.fc.controller;

import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import department.fc.common.AttributeAndView;
import department.fc.common.Controller;
import department.fc.domain.Department;
import department.fc.service.DepartmentService;

public class RegisterDepartmentController implements Controller {

	@Override
	public AttributeAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		// 1. 요청파라미터 조회 (부서_id, 부서명, 지점)
		String departmentId = request.getParameter("departmentId");
		String departmentName = request.getParameter("departmentName");
		String location = request.getParameter("location");

		// 2. 업무로직 처리 - DepartmentDAO 메소드 이용
		DepartmentService service = DepartmentService.getInstance();
		Department department = new Department(departmentId, departmentName,
				location);
		
		AttributeAndView av = null;
		try{
		service.registerDepartment(department);
		av = new AttributeAndView(false, "/WEB-INF/jsp/dept/department_detail.jsp");
		}catch (Exception e){
		av = new AttributeAndView(false, "/WEB-INF/jsp/error.jsp");
		}
		return av;

	}

}
